﻿#region LGPL License

/*
OpenSearchNet
Copyright (c) 2014, Brad Hards <bradh@frogmouth.net>, All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3.0 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library.
*/

#endregion LGPL License

using System;
using System.Globalization;

namespace OpenSearch.Osdd
{
    /// <summary>
    /// Image entry for OpenSearch Description Document
    /// </summary>
    public class Image
    {
        private int height;
        private int width;
        private string mimetype = "";
        private System.Uri uri;

        internal Image(System.Xml.XmlReader reader)
        {
            if (reader["height"] != null)
            {
                height = Int32.Parse(reader["height"] as string, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            if (reader["width"] != null)
            {
                width = Int32.Parse(reader["width"] as string, NumberStyles.Integer, CultureInfo.InvariantCulture);
            }
            mimetype = reader["type"];
            uri = new System.Uri(reader.ReadString());
        }

        /// <summary>
        /// Height of this image in pixels
        /// </summary>
        /// <remarks>
        /// <para>The server does not need to provide this information, so you may receive a default (0) value.</para>
        /// <para>The OpenSearch specification requires that this be non-negative. That requirement is not enforced by this property</para>
        /// </remarks>
        public int Height
        {
            get { return height; }
        }

        /// <summary>
        /// Width of this image in pixels
        /// </summary>
        /// <remarks>
        /// <para>The server does not need to provide this information, so you may receive a default (0) value.</para>
        /// <para>The OpenSearch specification requires that this be non-negative. That requirement is not enforced by this property</para>
        /// </remarks>
        public int Width
        {
            get { return width; }
        }

        /// <summary>
        /// Format of the image (MIME type)
        /// </summary>
        /// <remarks>
        /// <para>The server does not need to provide this information, so you may receive a default (empty string) value.</para>
        /// </remarks>
        public string MimeType
        {
            get { return mimetype; }
        }

        /// <summary>
        /// URL that identifies the location of an image that can be used in association with the search provider
        /// </summary>
        public System.Uri Uri
        {
            get { return uri; }
        }
    }
}